package member.api;

import member.api.vo.MemberCredisGiveVo;
import member.api.vo.MemberImportVo;
import member.api.vo.SendScoreVo;
import member.model.shop.Member;
import member.model.shop.MemberCreditsTran;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import utils.sql.PageVo;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by DixonLim on 2016/12/2.
 */
public interface MemberCreditsTranApi {

    public String toString();
    
    /**
     * 预扣用户积分 消费购物使用
     * @param memberCreditsTran
     * @return
     */
    public MemberCreditsTran holdMemberCreditsTran(MemberCreditsTran memberCreditsTran);

    /**
     * 保存memberCreditsTran
     * @param memberCreditsTran
     * @return
     */
    public MemberCreditsTran saveMemberCreditsTran(MemberCreditsTran memberCreditsTran);

    //根据id查询
    public MemberCreditsTran findMemberCreditsTranById(String id);

    /**
     * 赠送积分
     * sendType:1为企业 sendType:0为会员
     * @param sendScoreVo
     * @return
     * MemberCreditsTranApi.sendScore
     */
    public Map<String,Object> sendScore(SendScoreVo sendScoreVo);

    /**
     * 查询赠送方
     * @param sendType
     * @param sendUserId
     * @return
     */
    public List<MemberCreditsTran> findBySendTypeAndSendUserId(String sendType, String sendUserId);

    /**
     * 查询被赠送方
     * @param targetMemberId
     * @return
     */
    public List<MemberCreditsTran> findByTargetMemberId(String targetMemberId);

    /**
     * 企业导入会员信息赠送积分
     * @param organizationId
     * @return
     */
    public Map<String,Object> importMemberScore(String organizationId,InputStream inputStream,Integer sheetNum) throws IOException;


    /**
     * 分页查询
     * @param pageable
     * @param memberId
     * @return
     */
    public Page<MemberCreditsTran> findByMemberId(Pageable pageable, String memberId);

    /**
     * 分页查询，memberId既是send也是target
     * @param pageable
     * @param memberId
     * @return
     */
    public Page<MemberCreditsTran> findByMemberIdSendAndTarget(Pageable pageable, String memberId);

    /**
     * 分页查询积分流水
     * @param pageable
     * @param memberId
     * @param sendType
     * @return
     */
    public Page<MemberCreditsTran> findByMemberId(Pageable pageable, String memberId,String sendType,int finished);

    public Integer findAwardScoreByMemberId(String memberId);

    /**
     * 根据id 和 名称查询
     * @param pageable
     * @param memberId
     * @param name
     * @return
     */
    public Page<Member> findByMemberIdAndName(Pageable pageable, String memberId,String name);

    public void exportMemberScore(List<MemberImportVo> memberImportVos, int sheetNum, String sheetName, String xlsName,HttpServletResponse response);

        /**
         * 积分赠与
         * @param score
         * @param memberId
         * @param targetMemberId
         * @param desc
         * @param remark
         * @param dataStr
         * @param sendName
         * @param targetName
         * @param organizationId
         * @param sendOrganizationName
         * @param targetOrganizationId
         * @param targetOrganizationName
         * @return
         */
        public int awareMemberScore(int score, String memberId, String targetMemberId, String desc, String remark,
                                    String dataStr,String sendName,String targetName, String organizationId,String sendOrganizationName,
                                    String targetOrganizationId,String targetOrganizationName);
    public Page<MemberCreditsTran> findBySendNameAndSendMobileAndSendEmailAndSendDateBetween(String sendName,String sendMobile,String sendEmail,String dataStart,String dateEnd,Pageable pageable) throws ParseException;

    public Page<MemberCreditsTran> findByTargetNameAndTargetMobileAndTargetEmailAndSendDateBetween(String targetName,String targetMobile,String targetEmail,String dateStart,String dateEnd,Pageable pageable) throws ParseException;

    public Page<MemberCreditsTran> findMemberCreditsTranByTargetOrganizationNameAndSendTypeAndSendDate(String targetOrganizationName,String sendType,String dateStart,String dateEnd,Pageable pageable) throws ParseException;

    public void paySuccessed(String creditsHisId);

    /**
     * 积分授予总值(企业)
     * @param memberId
     * @return
     */
    public Integer findScoreAwardByMemberId(String memberId);

    /**
     * 积分赠送总值
     * @param memberId
     * @return
     */
    public Integer findScoreGiveByMemberId(String memberId);

    /**
     * 积分获赠总值
     * @param memberId
     * @return
     */
    public Integer findScoreGetByMemberId(String memberId);

    /**
     * 积分消费总值
     * @param memberId
     * @return
     */
    public Integer findScoreConsumeByMemberId(String memberId);

    //查询出会员被赠与的未完成的单
    public Boolean findReceMemberCreditsTranAndSetFinished() throws Exception;

    public Map sendSMSAndEmailToMember() throws Exception;

    void cancelTran(String creditsHisId);

    Integer findAwardScoreByMemberIdAndType(String memberId, String sendType);
}
